﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoodMan.Engine.ExServer.Cache;

namespace GoodMan.Portal.Biz
{
    public class iCache
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="key"></param>
        /// <param name="loadAction"></param>
        /// <param name="Duration">单位(s)</param>
        /// <returns></returns>
        public static T Get<T>(string key, Func<T> loadAction,int duration) 
            where T : class
        {
            T data = CacheBag.GetCache<T>(key);
            if (data == null)
            {
                data = loadAction.Invoke();
                if (data != null)
                {
                    return CacheBag.Add<T>(key, data, CacheExpireStrategy.Absolute, new TimeSpan(0, 0, duration));
                }
            }
            return data;
        }
        public static void Expire(string key)
        {
            CacheBag.RemoveCache(key);
        }
    }
}
